Skip to content

Fix metrics test cancellation race - #1816

Merged
simongdavies merged 2 commits into
mainfrom
simongdavies-metrics-test-cancellation
Sep 10, 2026
Merged

Fix metrics test cancellation race#1816
simongdavies merged 2 commits into
mainfrom
simongdavies-metrics-test-cancellation

Conversation

@simongdavies

Copy link
Copy Markdown
Member

Summary

The metrics test cancels its guest from a host callback. Cancellation targets the intended call without depending on scheduling delays. The test asserts ExecutionCanceledByHost and the callback duration metric.

Fixes #1815.

Validation

  • The targeted test passes locally on Windows with default features and with function_call_metrics.
  • just fmt-apply and just clippy pass.
  • macOS HVF execution needs CI confirmation.

Cancel the guest from a host callback so metric assertions do not depend on scheduling delays.

Fixes #1815

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 9, 2026 17:17
@simongdavies simongdavies added area/testing Related to tests or testing infrastructure kind/bugfix For PRs that fix bugs ready-for-review PR is ready for (re-)review labels Sep 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The updated test expects 5 metrics but does not currently assert all expected metric keys, which can allow incorrect metric emission to slip through.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes flakiness in the host-side metrics test by canceling guest execution deterministically from a host callback, avoiding timing-based sleeps and asserting the expected cancellation error and emitted duration metrics.

Changes:

  • Replace time-delayed cancellation (sleep + thread) with a host-function callback that triggers cancellation at a deterministic point.
  • Update the test to call CallHostThenSpin and assert ExecutionCanceledByHost.
  • Extend metrics assertions to include the guest function name change and the new host callback duration metric.
File summaries
File Description
src/hyperlight_host/src/metrics/mod.rs Makes the metrics test cancellation deterministic via a host callback and adjusts expected metrics/labels accordingly.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/hyperlight_host/src/metrics/mod.rs Outdated
ludfjig
ludfjig previously approved these changes Sep 9, 2026

@ludfjig ludfjig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea calling kill from a host function (I guess slightly changes behavior in that we don't re-enter the vm rather than interrupt runnign vm, but metric is emitted in either case)

Check HostPrint and CancelGuest histograms so every expected metric key is covered.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
@simongdavies
simongdavies enabled auto-merge (squash) September 9, 2026 18:49
@simongdavies
simongdavies merged commit 246b765 into main Sep 10, 2026
95 of 101 checks passed
@simongdavies
simongdavies deleted the simongdavies-metrics-test-cancellation branch September 10, 2026 08:23
@github-actions github-actions Bot removed the ready-for-review PR is ready for (re-)review label Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/testing Related to tests or testing infrastructure kind/bugfix For PRs that fix bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

metrics::tests::test_metrics_are_emitted test is flaky on macOS

3 participants